package com.abel;

import org.apache.ignite.Ignite;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.ConnectorConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xiachao
 * @date 2019-04-28
 */
@Configuration
public class IgniteConf {

    private int ignitePort = 8899;

    @Bean
    IgniteConfiguration igniteConfiguration(){

        CacheConfiguration cacheConf = new CacheConfiguration();
        cacheConf.setBackups(3);
        cacheConf.setName("");
        //分区模式
        cacheConf.setCacheMode(CacheMode.LOCAL);
        cacheConf.setName("COMMON");
        IgniteConfiguration cfg = new IgniteConfiguration();
        cfg.setCacheConfiguration(cacheConf);
        //采用服务端模式
        cfg.setClientMode(false);
        ConnectorConfiguration connectorConf = new ConnectorConfiguration();
        connectorConf.setPort(ignitePort);

        return cfg;
    }

    @Bean(destroyMethod = "close")
    Ignite ignite(IgniteConfiguration igniteConf){
        final Ignite ignite = Ignition.start(igniteConf);
        ignite.cluster().active(true);
        return ignite;
    }

}
